package com.gjs.cd.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gjs.cd.pojo.dto.CdDetailReq;
import com.gjs.cd.pojo.dto.StatusReq;
import com.gjs.cd.pojo.vo.CdDetailVo;
import com.gjs.cd.pojo.entity.CdDetail;
import com.gjs.cd.service.ICdDetailService;
import com.gjs.common.manager.response.RspBody;
import com.gjs.common.pojo.dto.request.PageQuery;
import com.gjs.common.pojo.dto.response.ListPageRsp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhongwenguang
 * @date 2022-3-16 9:24
 */
@RestController
@Slf4j
@Api(tags = "年度管理")
@RequestMapping("/cd_detail")
@RequiredArgsConstructor
public class CdDetailController {
    private final ICdDetailService cdDetailService;

    //获取list
    @GetMapping("/list")
    @ApiOperation("查询分页")
    public RspBody<ListPageRsp<CdDetailVo>> list(PageQuery pageQuery,CdDetailReq cdDetailReq){
        IPage<CdDetailVo> cdDetailVoIPage = cdDetailService.getList(pageQuery,cdDetailReq);
        return RspBody.success(ListPageRsp.of(cdDetailVoIPage,CdDetailVo.class));
    }

    //下架操作，批量操作
    @PostMapping("/put_or_off")
    @ApiOperation("上下架")
    public RspBody<Boolean> putOrOff(@RequestBody List<StatusReq> list){
        return RspBody.success(cdDetailService.putOrOff(list));
    }
    //下架操作，单个操作
    @PostMapping("/put_or_off_one")
    @ApiOperation("上下架")
    public RspBody<Boolean> putOrOffOne(StatusReq statusReq){
        return RspBody.success(cdDetailService.putOrOffOne(statusReq));
    }
    //新增
    @PostMapping("/save_or_update")
    @ApiOperation("新增或更新")
    public RspBody<Boolean> save(CdDetail cdDetail){
        return RspBody.success(cdDetailService.saveOrUpdate(BeanUtil.copyProperties(cdDetail,CdDetail.class)));
    }

    //详情
    @GetMapping("/detail")
    @ApiOperation("获取详情")
    public RspBody<CdDetail> detail(Long id){
        return RspBody.success(cdDetailService.getById(id));

    }

}
